package com.ylz.tedi.myapplication;

import android.content.Context;
import android.graphics.SurfaceTexture;
import android.view.TextureView;

public class CeShi implements TextureView.SurfaceTextureListener{

    public PlayerVideoThread getThread() {
        return thread;
    }

    private PlayerVideoThread thread;

    private Context context;
    private String message;

    public CeShi(Context context,String message){
        this.context=context;
        this.message=message;
    }

    /**
     * 初始化好SurfaceTexture后调用
     * @param surfaceTexture
     * @param i
     * @param i1
     */
    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
        //开启一个线程去播放视频
        thread=new PlayerVideoThread(context,message,surfaceTexture);
        thread.start();
    }

    /**
     * 视频尺寸改变后调用
     * @param surfaceTexture
     * @param i
     * @param i1
     */
    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i1) {

    }

    /**
     * SurfaceTexture即将被销毁时调用
     * @param surfaceTexture
     * @return
     */
    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {

//            mMediaPlayer.stop();
//            mMediaPlayer.release();
//            mMediaPlayer=null;
        thread.stops();
        return true;
    }

    /**
     * 通过SurfaceTexture.updateteximage()更新指定的SurfaceTexture时调用
     * @param surfaceTexture
     */
    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {

    }
}


